package com.caigou.service.impl;

import com.caigou.bean.cms.entity.ArticleSpecialAnnotation;
import com.caigou.bean.cms.param.ArticleSpecialAnnotationDataParam;
import com.caigou.mapper.cms.ArticleSpecialAnnotationMapper;
import com.caigou.pojo.ArticleSpecialAnnotationData;
import com.caigou.service.ArticleSpecialAnnotationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleSpecialAnnotationServiceImpl implements ArticleSpecialAnnotationService {

    @Resource
    private ArticleSpecialAnnotationMapper articleSpecialAnnotationMapper;

    @Override
    public ArticleSpecialAnnotation saveArticleSpecialAnnotationData(String articleId, String title, String content) {
        ArticleSpecialAnnotation annotation = new ArticleSpecialAnnotation();
        annotation.setArticleId(articleId);
        annotation.setTitle(title);
        annotation.setContent(content);
        articleSpecialAnnotationMapper.saveArticleSpecialAnnotationData(annotation);
        return annotation;
    }

    @Override
    public List<ArticleSpecialAnnotationData> loadArticleSpecialAnnotationData(String articleId) {
        return articleSpecialAnnotationMapper.loadArticleSpecialAnnotationData(articleId);
    }

    @Override
    public void deleteArticleSpecialAnnotation(Integer id) {
        articleSpecialAnnotationMapper.deleteArticleSpecialAnnotation(id);
    }

    @Override
    public int deleteArticleSpecialAnnotationByArticleId(String articleId){
        return articleSpecialAnnotationMapper.deleteArticleSpecialAnnotationByArticleId(articleId);
    }

    @Override
    public void updateArticleSpecialAnnotationData(ArticleSpecialAnnotationDataParam item) {
        if (null == item.getId()){
            // 这条是新增的数据
            ArticleSpecialAnnotation annotation = new ArticleSpecialAnnotation();
            annotation.setArticleId(item.getArticleId());
            annotation.setTitle(item.getTitle());
            annotation.setContent(item.getContent());
            articleSpecialAnnotationMapper.saveArticleSpecialAnnotationData(annotation);
        } else {
            // 这条是修改的数据
            articleSpecialAnnotationMapper.updateArticleSpecialAnnotationData(item);
        }
    }
}
